/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       dialog_enemy_runs.cpp

	$Header: /game/dialog_enemy_runs.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "dialog_enemy_runs.h"

#include "bitmap_group.h"
#include "bitmap_group_cache.h"
#include "bitmap_layer_window.h"
#include "bound_handler.h"
#include "button.h"
#include "external_string.h"
#include "standard_fonts.h"
#include "text_window.h"

static t_bitmap_group_cache k_bitmaps( "dialog.enemy_runs" );
static t_external_string const k_text_question( "enemy_runs_question.misc" );
static t_external_string const k_text_run( "enemy_runs_run.misc" );
static t_external_string const k_text_fight( "enemy_runs_fight.misc" );
static t_external_string const k_text_quick_combat( "enemy_runs_quick_combat.misc" );

t_dialog_enemy_runs::t_dialog_enemy_runs( t_window* parent )
				   : t_window( k_completely_transparent, parent )
{
	t_bitmap_layer_window*	background;
	t_bitmap_layer const*	layer;
	t_button*				button;

	m_bitmaps = k_bitmaps.get();
	layer = m_bitmaps->find( "background" );
	background = new t_bitmap_layer_window( layer, t_screen_point(0,0), this );
	set_drop_shadow( true );

	t_button_handler handler;

	button = create_button( m_bitmaps, "run", background, t_screen_point(0,0));
	handler = bound_handler( *this, &t_dialog_enemy_runs::run_clicked );
	button->set_click_handler( handler );

	button = create_button( m_bitmaps, "fight", background, t_screen_point(0,0));
	handler = bound_handler( *this, &t_dialog_enemy_runs::fight_clicked );
	button->set_click_handler( handler );

	button = create_button( m_bitmaps, "quick_combat", background, t_screen_point(0,0));
	handler = bound_handler( *this, &t_dialog_enemy_runs::quick_combat_clicked );
	button->set_click_handler( handler );

	t_text_window*	text_window;
	t_screen_rect	rect;

	rect = m_bitmaps->find( "text" )->get_rect();
	text_window = new t_text_window( get_font( 20 ), rect, background, k_text_question, t_pixel_24(0,0,0));
	text_window->set_center_horizontal();
	text_window->set_center_vertical();
	
	rect = m_bitmaps->find( "run_text" )->get_rect();
	text_window = new t_text_window( get_font( rect.height() ), rect, background, k_text_run,
									 t_pixel_24(0,0,0));
	
	rect = m_bitmaps->find( "fight_text" )->get_rect();
	text_window = new t_text_window( get_font( rect.height() ), rect, background, k_text_fight,
									 t_pixel_24(0,0,0));

	rect = m_bitmaps->find( "quick_combat_text" )->get_rect();
	text_window = new t_text_window( get_font( rect.height() ), rect, background, k_text_quick_combat,
									 t_pixel_24(0,0,0));

	rect = background->get_client_rect();

	rect += (parent->get_client_rect().size() - rect.size()) / 2;
	init( rect );
}

void t_dialog_enemy_runs::run_clicked( t_button* )
{
	m_enemy_ran = true;
	close();
}

void t_dialog_enemy_runs::fight_clicked( t_button* )
{
	m_enemy_ran = false;
	m_use_quick_combat = false;
	close();
}

void t_dialog_enemy_runs::quick_combat_clicked( t_button* )
{
	m_enemy_ran = false;
	m_use_quick_combat = true;
	close();
}
